package com.epoch.controller;

import com.epoch.entity.Consumer;
import com.epoch.service.ConsumerService;
import com.epoch.utils.Base;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author admin
 */
@RestController
@Slf4j
public class ConsumerController {

    @Autowired
    private ConsumerService consumerService;

    @GetMapping("/")
    public String index(){
        return "index";
    }

    @GetMapping("consumer")
    public Consumer getConsumerById(String csId){
        log.info("ConsumerController: "+csId);
        return consumerService.getById(csId);
    }

    @GetMapping("login")
    public Consumer login(String csPhone, String csPwd){
        log.info("Controller "+csPhone+" "+csPwd);
        String csPwdEncode = Base.encode(csPwd);
        log.info("加密后的密码是："+csPwdEncode);
        log.info(csPhone+"登录...");
        return consumerService.login(csPhone, csPwdEncode);
    }
}
